package com.example.geguo.deeplinkdemo;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import java.lang.ref.WeakReference;

/**
 * 作者  格锅
 * 时间  2017/1/19 11:39
 * 文件  DeepLink
 * 1、将内部类 静态化
 * 2、使用弱引用 增加一个Activity的引用，同时又不影响Activity内存的回收
 */

public class HandlerFixActivity extends Activity{

		public static void startActivity(Context context){
				Intent intent = new Intent(context,HandlerFixActivity.class);
				context.startActivity(intent);
			}

	private static class MyHandler extends Handler{
		private final WeakReference<HandlerFixActivity> mActivity;
		private MyHandler(HandlerFixActivity handlerFixActivity) {
			mActivity = new WeakReference<HandlerFixActivity>(handlerFixActivity);
		}

		@Override
		public void handleMessage(Message msg) {
			HandlerFixActivity activity = mActivity.get();
			if (activity!=null){
//				持有外部的引用

			}
		}
	}

	private final MyHandler mHandler = new MyHandler(this);
	private static final  Runnable sRunnable = new Runnable() {
		@Override
		public void run() {

		}
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_handler);
		// Post a message and delay its execution for 10 minutes.
		mHandler.postDelayed(sRunnable, 1000 * 60 * 10);

		// Go back to the previous Activity.
		finish();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		System.out.println(this.getClass().getSimpleName() + ":onDestroy");
	}

	//	强制回收该方法不会执行哦
	@Override
	protected void finalize() throws Throwable {
		super.finalize();
		System.out.println(this.getClass().getSimpleName() + ":finalize");
	}
}
